Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.

Note: Your solution should be in logarithmic time complexity.

Solution:

  1. public class Solution {
  2. public int trailingZeroes(int n) {
  3. int res = 0;
  4. while (n > 0) {
  5. n /= 5;
  6. res += n;
  7. }
  8. return res;
  9. }
  10. }